include $(RVR_ROOT)/defs.mk

INCS =-I$(SERIAL_COMM_INC) -I$(PORT_COMM_INC) -I$(JOYSTICK_INC) -I$(CONFIG_INC)
LIBS =-L$(SERIAL_COMM_LIB) -L$(PORT_COMM_LIB) -L$(JOYSTICK_LIB) -L$(CONFIG_LIB)

CFLAGS=-c -g -Wall $(INCS)
LDFLAGS=$(LIBS) -lportcomm -lserialcomm
SOURCES=input_state.cpp input_reader.cpp rover_state.cpp util.cpp command.cpp commander.cpp
OBJECTS=$(SOURCES:.cpp=.o)
LOC_OBJ=$(addprefix lib/, $(OBJECTS))
EXECUTABLE=
LIB_NAME=libroverutil.a

all: $(SOURCES) $(EXECUTABLE)

lib: $(OBJECTS)
	$(AR) $(ARFLAGS) lib/$(LIB_NAME) $(LOC_OBJ)

# $@ is target, e.g Executable
$(EXECUTABLE): $(OBJECTS)
	mkdir -p bin
	$(CC) $(LOC_OBJ) -o bin/$@ $(LDFLAGS)

# prerequites is $<
.cpp.o:
	mkdir -p lib
	$(CC) $(CFLAGS) $(LDFLAGS)  $< -o lib/$@

clean:
	rm -rf *~ include/*~ bin lib

run:
	./bin/$(EXECUTABLE)